package stark.app.frame.baseclassuse;

import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import stark.app.R;
import stark.app.databinding.FragmentLoadMoreAdapterUseBinding;
import stark.app.frame.baseclassuse.adapter.StkLoadMoreAdapter;
import stark.common.basic.adapter.BaseLoadMoreAdapter;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.bean.StkResourceBean;

/**
 * Author：daizhongbin on 2021/8/6
 * Email：1027154338@qq.com
 * Desc:
 */
public class LoadMoreAdapterUseFragment extends BaseNoModelFragment<FragmentLoadMoreAdapterUseBinding> {

    @Override
    protected int onCreate() {
        return R.layout.fragment_load_more_adapter_use;
    }

    @Override
    protected void initView() {
        GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 3);
        mDataBinding.rvData.setLayoutManager(layoutManager);

        StkLoadMoreAdapter loadMoreAdapter = new StkLoadMoreAdapter();
        mDataBinding.rvData.setAdapter(loadMoreAdapter);
        mDataBinding.smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                loadMoreAdapter.reqFirstPageData(new BaseLoadMoreAdapter.ILoadDataCallback<StkResourceBean>() {
                    @Override
                    public void onLoadedData(boolean success, @Nullable List<StkResourceBean> stkResourceBeans) {
                        mDataBinding.smartRefreshLayout.finishRefresh(success);
                    }
                });
            }
        });
        mDataBinding.smartRefreshLayout.autoRefresh();

    }

    @Override
    protected void initData() {
    }
}
